package com.jrtc.backend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.base.Strings;
import com.jrtc.base.config.dto.ResultDTO;
import com.jrtc.base.config.dto.ResultDTOBuilder;
import com.jrtc.base.entity.bo.PrescriptionLabelTwo;
import com.jrtc.service.PrescriptionLabelTwoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 运动处方标签二级分类(PrescriptionLabelTwo)表控制层
 *
 * @author makejava
 * @since 2022-09-08 13:36:24
 */
@RestController
@RequestMapping("prescriptionLabelTwo")
public class PrescriptionLabelTwoController {
    /**
     * 服务对象
     */
    @Resource
    private PrescriptionLabelTwoService prescriptionLabelTwoService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public PrescriptionLabelTwo selectOne(Integer id) {
        return this.prescriptionLabelTwoService.queryById(id);
    }
    
    @RequestMapping("getPrescriptionLabelTwoList")
    public ResultDTO getPrescriptionLabelTwoList(@RequestBody PrescriptionLabelTwo prescriptionLabelTwo)
    {
        IPage<PrescriptionLabelTwo> ipage = prescriptionLabelTwoService.queryPrescriptionLabelTwoList(prescriptionLabelTwo);
        return ResultDTOBuilder.success(ipage);
    }

    @RequestMapping("insertPrescriptionLabelTwo")
    public ResultDTO insertPrescriptionLabelTwo(@RequestBody PrescriptionLabelTwo prescriptionLabelTwo)
    {
        PrescriptionLabelTwo tmpPrescriptionLabelTwo = prescriptionLabelTwoService.insert(prescriptionLabelTwo);
        if (tmpPrescriptionLabelTwo != null)
        {
           return ResultDTOBuilder.success("添加成功！");
        }
        return ResultDTOBuilder.failureMsg("添加失败！");
    }

    @RequestMapping("getPrescriptionLabelTwoById")
    public ResultDTO getPrescriptionLabelTwoById(@RequestBody Map<String, String> map)
    {
        String prescriptionLabelTwoId = map.get("prescriptionLabelTwoId");
        PrescriptionLabelTwo prescriptionLabelTwo = prescriptionLabelTwoService.queryById(Integer.valueOf(prescriptionLabelTwoId));
        if (Strings.isNullOrEmpty(prescriptionLabelTwoId) || prescriptionLabelTwo==null)
        {
            return ResultDTOBuilder.failureMsg("信息有误！");
        }
        return ResultDTOBuilder.success(prescriptionLabelTwo);
    }

    @RequestMapping("updatePrescriptionLabelTwo")
    public ResultDTO updatePrescriptionLabelTwo(@RequestBody PrescriptionLabelTwo prescriptionLabelTwo)
    {
        if (prescriptionLabelTwo==null)
        {
            return ResultDTOBuilder.failureMsg("信息有误！");
        }
        if (prescriptionLabelTwoService.update(prescriptionLabelTwo)!=null)
        {
            return ResultDTOBuilder.success("修改信息成功！");
        }
        return ResultDTOBuilder.failureMsg("修改信息失败！");
    }
    
    @RequestMapping("deletePrescriptionLabelTwo")
    public ResultDTO deletePrescriptionLabelTwo(@RequestBody Map<String,String> map)
    {
        String prescriptionLabelTwoId = map.get("prescriptionLabelTwoId");
        if (!Strings.isNullOrEmpty(prescriptionLabelTwoId))
        {
            if (prescriptionLabelTwoService.deleteById(Integer.valueOf(prescriptionLabelTwoId)))
            {
                return ResultDTOBuilder.success("删除成功！");
            }
            return ResultDTOBuilder.failureMsg("删除失败！");
        }
        return ResultDTOBuilder.failureMsg("编号不正确！");
    }
}